package org.skyeye.modeling.commands;

import java.util.ArrayList;

import org.eclipse.gef.commands.Command;
import org.skyeye.modeling.model.MBase;
import org.skyeye.modeling.model.MRoot;

public class ImportCommand extends Command{

	private MRoot ori;
	private MRoot obj;
	
	private MRoot temp;
	
	public MRoot getOri() {
		return ori;
	}

	public void setOri(MRoot ori) {
		this.ori = ori;
	}

	public MRoot getObj() {
		return obj;
	}

	public void setObj(MRoot obj) {
		this.obj = obj;
	}

	public void execute(){
		temp = new MRoot();
		temp.setNameMap(ori.getNameMap());
		for(MBase child :ori.getChildren()){
			temp.addChild(child);
		}
		ori.setChildren(new ArrayList<MBase>());
		for(MBase child : obj.getChildren()){
			ori.addChild(child);
		}

	}
	
	public void redo(){
		execute();
	}
	public void undo(){
//		for(MBase child :obj.getChildren()){
//			ori.removeChild(child);
//		}
		ori.setNameMap(temp.getNameMap());
		ori.setChildren(new ArrayList<MBase>());
		for(MBase child : temp.getChildren()){
			ori.addChild(child);
		}
	}
	
	public String getLabel() {
		return "Import";
	}
}
